/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.rlair;


import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Xu Dong Li
 */
public class Replace {

    //private static final Pattern p = Pattern.compile("[\\u4e00-\\u9fa5]+[\\u3002\\uff1b\\uff0c\\uff1a\\u201c\\u201d\\uff08\\uff09\\u3001\\uff1f\\u300a\\u300b||\\,\\:\\;]*[\\u4e00-\\u9fa5]*");

    private static final Pattern p = Pattern.compile("(\"|\')[A-Za-z0-9\\-\\(\\)（）？！\\!\\?\\:、；]*[\\u4e00-\\u9fa5]+[A-Za-z0-9\\-\\(\\)（）？！\\!\\?\\:、；\\u3002\\uff1b\\uff0c\\uff1a\\u201c\\u201d\\uff08\\uff09\\u3001\\uff1f\\u300a\\u300b||\\,\\:\\; \\u4e00-\\u9fa5]*(\"|\')");

    private static final Pattern qianp = Pattern.compile("[a-z|A-Z|>|<|\\s|\"|\"]");

    private static final Pattern quchu = Pattern.compile("[\\s|\t|\r|\n]");

    private static final Set<String> result = new TreeSet();

    private static final List<String> us = new ArrayList<>();
    private static final List<String> zh = new ArrayList<>();
    private static final List<String> keys = new ArrayList<>();

    private static final List<I18nEnty> entrys = new ArrayList<>();

    public static void main(String[] args) {

//        replace("E:\\workspace\\RuiliAirB2B\\rlairB2B-webcfg\\src\\main\\webapp\\WEB-INF\\views");
        //geni18n();
        //tongji();
        //resdString("D:\\test-i18");
        //tiHuangZhengLi();
        //Map<String, String> maps = getAllKey("D:\\workspace\\rloa\\oa-common\\src\\main\\resources\\common\\i18n\\messages.properties");
        //replaceJava(maps, "D:\\workspace\\rloa\\oa-web\\src\\main\\java\\net\\rlair\\oa");

        Map<String, String> maps = getAllKey("D:\\workspace\\rloa\\oa-common\\src\\main\\resources\\common\\i18n\\apiFtlMessages.properties");
        replaceApiFtl(maps, "D:\\workspace\\rloa\\oa-web\\src\\main\\webapp\\WEB-INF\\api");

    }

    private static void replaceApiFtl(Map<String, String> map, String path) {
        List<File> fileList = new ArrayList<>();
        File file = new File(path);
        if (file.isFile()) {
            fileList.add(file);
        } else {
            File[] files = file.listFiles();
            if (files == null) {
                return;
            }
            for (File f : files) {
                if (f.isFile()) {
                    fileList.add(f);
                } else if (f.isDirectory()) {
                    replaceApiFtl(map, f.getAbsolutePath());
                }
            }
        }

        for (File f1 : fileList) {
            try (InputStreamReader read = new InputStreamReader(new FileInputStream(f1), "UTF-8")) {
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                StringBuilder sb = new StringBuilder();
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    if (lineTxt == null) {
                        sb.append(lineTxt);
                        sb.append(System.getProperty("line.separator"));
                        continue;
                    }
                    //<#---->
                    final String temp = lineTxt.trim();
                    if (temp.startsWith("<#--")){
                        sb.append(lineTxt);
                        sb.append(System.getProperty("line.separator"));
                        continue;
                    }
                    final Matcher m = p.matcher(lineTxt);
                    final Map<String, String> needReplace = new HashMap<>();
                    while (m.find()) {
                        String group = m.group();
                        String groupT = group.substring(1, m.group().length()-1);
                        if (!map.containsKey(groupT)) {
                            System.out.println("未找到该中文的key:" + groupT);
                            continue;
                        }
                        needReplace.put(groupT, map.get(groupT).replaceAll("\\.", "_"));
                    }

                    for (final String re : needReplace.keySet()) {
                        lineTxt = lineTxt.replaceAll(re, "\\$\\{"+ needReplace.get(re) +"!\\}");
                    }
                    sb.append(lineTxt);
                    sb.append(System.getProperty("line.separator"));
                }
                PrintWriter printWriter = new PrintWriter(f1);
                printWriter.write(sb.toString().toCharArray());
                printWriter.close();
                printWriter.flush();

                //提取
            } catch (Exception ex) {
                Logger.getLogger(Replace.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }

    private static void replaceJava(Map<String, String> map, String path) {
        List<File> fileList = new ArrayList<>();
        File file = new File(path);
        if (file.isFile()) {
            fileList.add(file);
        } else {
            File[] files = file.listFiles();
            if (files == null) {
                return;
            }
            for (File f : files) {
                if (f.isFile()) {
                    fileList.add(f);
                } else if (f.isDirectory()) {
                    replaceJava(map, f.getAbsolutePath());
                }
            }
        }

        for (File f1 : fileList) {
            if ("JwtRsaService.java".equals(f1.getName()) || "FormCategoryServiceImpl.java".equals(f1.getName())) {
                continue;
            }
            boolean inputUtil = false;
            boolean hasChinese = false;
            boolean canInput = false;
            try (InputStreamReader read = new InputStreamReader(new FileInputStream(f1), "UTF-8")) {
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    if (lineTxt == null) {
                        continue;
                    }
                    if (lineTxt.contains("private MsgTranslateUtil msgTranslateUtil")) {
                        inputUtil = true;
                    }

                    if (!canInput) {
                        if (lineTxt.contains("@Service") || lineTxt.contains("@Resource")
                                || lineTxt.contains("@Component") || lineTxt.contains("@Controller")) {
                            canInput = true;
                        }
                    }

                    if (hasChinese) {
                        continue;
                    }

                    final String temp = lineTxt.trim();
                    if (temp.startsWith("//") || temp.startsWith("/*")
                            || temp.startsWith("@LogOpera") || temp.startsWith("*")
                            || temp.startsWith("*@a") || temp.startsWith("@Export")
                            || temp.startsWith("logger") || temp.startsWith("LOGGER")){
                        continue;
                    }

                    final Matcher m = p.matcher(lineTxt);
                    if (m.find()) {
                        hasChinese = true;
                    }
                }
            } catch (Exception ex) {
                System.out.println("==========错误=========" + ex.getMessage());
            }

            if (!hasChinese) {
                //System.out.println("该文件不存在中文" + f1.getName());
                continue;
            }

            if (!canInput) {
                System.out.println("======该文件存在中文但无法注入" + f1.getName());
                continue;
            }

            try (InputStreamReader read = new InputStreamReader(new FileInputStream(f1), "UTF-8")) {
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                StringBuilder sb = new StringBuilder();
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    if (lineTxt == null) {
                        sb.append(lineTxt);
                        sb.append(System.getProperty("line.separator"));
                        continue;
                    }
                    if ((!inputUtil) && lineTxt.startsWith("package net.rlair")) {
                        sb.append(lineTxt);
                        sb.append(System.getProperty("line.separator"));
                        sb.append("import net.rlair.oa.service.i18n.MsgTranslateUtil;");
                        sb.append(System.getProperty("line.separator"));
                        continue;
                    }
                    if ((!inputUtil) && (lineTxt.contains("class") || lineTxt.contains("Service")) && lineTxt.contains("{")) {
                        sb.append(lineTxt);
                        sb.append(System.getProperty("line.separator"));
                        sb.append("    /**");
                        sb.append(System.getProperty("line.separator"));
                        sb.append("     * 国际化工具.");
                        sb.append(System.getProperty("line.separator"));
                        sb.append("     */");
                        sb.append(System.getProperty("line.separator"));
                        sb.append("    @Resource");
                        sb.append(System.getProperty("line.separator"));
                        sb.append("    private MsgTranslateUtil msgTranslateUtil;");
                        sb.append(System.getProperty("line.separator"));
                        inputUtil = true;
                        continue;
                    }
                    final String temp = lineTxt.trim();

                    if (temp.startsWith("//") || temp.startsWith("/*")
                            || temp.startsWith("@LogOpera") || temp.startsWith("*")
                            || temp.startsWith("*@a") || temp.startsWith("@Export")
                            || temp.startsWith("logger") || temp.startsWith("LOGGER")){
                        sb.append(lineTxt);
                        sb.append(System.getProperty("line.separator"));
                        continue;
                    }
                    final Matcher m = p.matcher(lineTxt);
                    final Map<String, String> needReplace = new HashMap<>();
                    while (m.find()) {
                        String group = m.group();
                        String groupT = group.substring(1, m.group().length()-1);
                        if (!map.containsKey(groupT)) {
                            System.out.println("未找到该中文的key:" + groupT);
                            continue;
                        }
                        needReplace.put(group, map.get(groupT));
                    }

                    if (needReplace.size() > 0 && temp.contains(" static ")) {
                        System.out.println("====可能是静态常量，请人工确认:" + lineTxt.trim());
                        sb.append(lineTxt);
                        sb.append(System.getProperty("line.separator"));
                        continue;
                    }

                    for (final String re : needReplace.keySet()) {
                        final String linTep = lineTxt.replaceAll(re, "msgTranslateUtil.getMessage(\"" + needReplace.get(re) + "\")");
                        if (linTep.contains("'")) {
                            System.out.println("====替换可能会发生错误，请人工确认:" + lineTxt.trim());
                        } else {
                            lineTxt = linTep;
                        }
                    }

                    if (needReplace.size() > 0) {
                        while (lineTxt.length() > 140) {
                            //需要换行
                            final String[] split = lineTxt.split("\\.getMessage\\(", 2);
                            if (split.length == 2) {
                                sb.append(split[0] + ".getMessage(");
                                sb.append(System.getProperty("line.separator"));
                                lineTxt = "          " + split[1];
                            } else {
                                break;
                            }
                        }
                    }

//                    for (Map.Entry<String, String> e : xutihuan.entrySet()) {
//                        lineTxt = lineTxt.replace("<@spring.message \"" + e.getKey() + "\"", "<@spring.message \"" + e.getValue() + "\"");
//                    }
                    sb.append(lineTxt);
                    sb.append(System.getProperty("line.separator"));
                }
                PrintWriter printWriter = new PrintWriter(f1);
                printWriter.write(sb.toString().toCharArray());
                printWriter.close();
                printWriter.flush();

                //提取
            } catch (Exception ex) {
                Logger.getLogger(Replace.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }

    private static Map<String,String> getAllKey(String path) {
        final Map<String, String> m = new HashMap<>();
        try (InputStreamReader read = new InputStreamReader(new FileInputStream(path), "UTF-8")) {
            BufferedReader bufferedReader = new BufferedReader(read);
            String lineTxt = null;
            while ((lineTxt = bufferedReader.readLine()) != null) {
                if (lineTxt == null) {
                    continue;
                }
                lineTxt = lineTxt.trim();

                if (lineTxt.startsWith("#") || "".equals(lineTxt) || !lineTxt.contains("=")){
                    continue;
                }

//                if (lineTxt.endsWith(",")) {
//                    lineTxt = lineTxt.substring(0, lineTxt.length() - 1);
//                }
                if (convert(lineTxt).trim().length() > 0) {
                    lineTxt = convert(lineTxt);
                }
                String[] ss = lineTxt.split("=", 2);
                if (ss.length != 2) {
                    System.out.println("数据错误：" + lineTxt);
                    continue;
                }

                final String[] split = ss[1].split("///");
                for (String s : split) {
                    if (m.containsKey(s)) {
                        System.out.println("提取中文重复：" + s);
                        continue;
                    }
                    m.put(s, ss[0]);   //中文，key
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(Replace.class.getName()).log(Level.SEVERE, null, ex);
        }
        return m;
    }

    public static void tongji() {
        Map<String, String> serviceUs = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\service\\messages_en_US.properties", 0, true);
        Map<String, String> serviceZh = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\service\\messages_zh_CN.properties", 0, true);
        save(serviceUs, serviceZh);
        createdI18s(serviceUs, serviceZh);

        Map<String, String> serviceVUs = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\service\\validationMessages_en_US.properties", 0, true);
        Map<String, String> serviceVZh = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\service\\validationMessages_zh_CN.properties", 0, true);
        save(serviceVUs, serviceVZh);
        createdI18s(serviceVUs, serviceVZh);

//        Map<String, String> webJsUs = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\web\\en-US.json", 0, false);
//        Map<String, String> webJsZh = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\web\\zh-CN.json", 0, true);
//        save(webJsUs, webJsZh);
//        createdI18s(webJsUs, webJsZh);
        Map<String, String> webUs = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\web\\messages_en_US.properties", 0, true);
        Map<String, String> webZh = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\web\\messages_zh_CN.properties", 0, true);
        save(webUs, webZh);
        createdI18s(webUs, webZh);

//        Map<String, String> webcfgJsUs = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\webcfg\\en-US.json", 0, false);
//        Map<String, String> webcfgJsZh = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\webcfg\\zh-CN.json", 0, true);
//        save(webcfgJsUs, webcfgJsZh);
//        createdI18s(webcfgJsUs, webcfgJsZh);
        Map<String, String> webcfgUs = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\webcfg\\messages_en_US.properties", 0, true);
        Map<String, String> webcfgZh = readI18n("C:\\Users\\Administrator\\Desktop\\ii\\webcfg\\messages_zh_CN.properties", 0, true);
        save(webcfgUs, webcfgZh);
        createdI18s(webcfgUs, webcfgZh);

        final List<I18nEnty> chufus = chufu();
        chufus.sort((o1, o2) -> {
            if (o1.zh.length() > o2.zh.length()) {
                return 1;
            }
            if (o1.zh.length() < o2.zh.length()) {
                return -1;
            }
            final char[] chars1 = o1.zh.toCharArray();
            final char[] chars2 = o2.zh.toCharArray();
            for (int i = 0; i < chars1.length; i++) {
                if (chars1[i] > chars2[i]) {
                    return 1;
                }
                if (chars1[i] < chars2[i]) {
                    return -1;
                }
            }

            return 0;
        });
        final Set<String> set = new HashSet<>();
        for (I18nEnty s : chufus) {
            System.out.println(s.key + "`=`" + s.zh + "`=`" + s.us + "````" + s.key + "`=`" + s.us);
            set.add(s.zh);
        }
        System.out.println(set.size());

    }

    public static List<I18nEnty> chufu() {
        final List<I18nEnty> list = new ArrayList<>();
        for (int i = 0; i < entrys.size(); i++) {
            for (int j = 0; j < entrys.size(); j++) {
                if (i == j) {
                    continue;
                }
                if (entrys.get(i).zh.equals(entrys.get(j).zh)
                        && !entrys.get(i).us.trim().replace(" ", "").toLowerCase()
                                .equals(entrys.get(j).us.trim().replace(" ", "").toLowerCase())) {

                    boolean exist = true;
                    for (I18nEnty enty : list) {
                        if (entrys.get(i).us.trim().replace(" ", "").toLowerCase().equals(enty.us.trim().replace(" ", "").toLowerCase())) {
                            exist = false;
                            break;
                        }
                    }
                    if (exist) {
                        list.add(entrys.get(i));
                    }
                }
            }
        }
        return list;
    }

    public static void createdI18s(Map<String, String> usMap, Map<String, String> zhMap) {
        for (Map.Entry<String, String> entry : usMap.entrySet()) {
            final String temp = entry.getValue();
            final String[] ss = temp.split("=", 2);
            final String key = ss[0];
            final String us = ss[1];

            final I18nEnty enty = new I18nEnty();
            enty.key = key;
            enty.us = us;
            enty.zh = zhMap.get(key).split("=", 2)[1];
            entrys.add(enty);
        }

    }

    public static void save(Map<String, String> usMap, Map<String, String> zhMap) {
        for (Map.Entry<String, String> entry : usMap.entrySet()) {
            final String temp = entry.getValue();
            final String[] ss = temp.split("=", 2);

            final String key = ss[0];
            final String value = ss[1];
            int index = zh.indexOf(zhMap.get(key).split("=", 2)[1]);

            us.add(value);
            zh.add(zhMap.get(key).split("=", 2)[1]);
            keys.add(key);
        }
    }

    //生产新的i18n文件
    public static void geni18n() {
        resdString("E:\\workspace\\RuiliAirB2B\\rlairB2B-webcfg\\src\\main\\webapp\\WEB-INF\\views");
        //总的i18n
        Map<String, String> zhI18n = readI18n("C:\\Users\\Administrator\\Desktop\\B2B\\JC\\i18n-zh.txt", 1, false);
        Map<String, String> enI18n = readI18n("C:\\Users\\Administrator\\Desktop\\B2B\\JC\\i18n-us.txt", 0, false);
        //自己的i18n
        Map<String, String> myI18n = readI18n("E:\\workspace\\RuiliAirB2B\\rlairB2B-webcfg\\src\\main\\resources\\i18n\\web\\messages_zh_CN.properties", 1, true);

        final List<String> ss = new ArrayList<>();
        final StringBuilder zhSb = new StringBuilder();
        final StringBuilder enSb = new StringBuilder();
        for (String s : result) {

            if (myI18n.containsKey(s)) {
                continue;
            }
            if (zhI18n.containsKey(s)) {
                final String[] temps = zhI18n.get(s).split("=");
                if (temps.length != 2) {
                    continue;
                }
                final String key = temps[0];
                if (enI18n.containsKey(key)) {
                    zhSb.append(zhI18n.get(s));
                    zhSb.append(System.getProperty("line.separator"));
                    enSb.append(enI18n.get(key));
                    enSb.append(System.getProperty("line.separator"));
                    continue;
                }
            }
            ss.add(s);
            System.out.println(s);
        }
        System.out.println(ss.size());
        System.out.println("=======中文=======");
        System.out.println(zhSb.toString());
        System.out.println("=======英文=======");
        System.out.println(enSb.toString());

    }

    //开始替换
    private static void replace(final String path, final Map<String, String> xutihuan) {

        System.out.println(path);
        List<File> fileList = new ArrayList<>();
        File file = new File(path);
        if (file.isFile()) {
            fileList.add(file);
        } else {
            File[] files = file.listFiles();
            if (files == null) {
                return;
            }
            for (File f : files) {
                if (f.isFile()) {
                    fileList.add(f);
                } else if (f.isDirectory()) {
                    replace(f.getAbsolutePath(), xutihuan);
                }
            }
        }

        for (File f1 : fileList) {
            try (InputStreamReader read = new InputStreamReader(new FileInputStream(f1), "UTF-8")) {
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                StringBuilder sb = new StringBuilder();
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    if (lineTxt == null) {
                        sb.append(lineTxt);
                        sb.append(System.getProperty("line.separator"));
                        continue;
                    }
                    final String temp = lineTxt.trim();
                    if (temp.startsWith("<#--") || temp.startsWith("<!--")) {
                        sb.append(lineTxt);
                        sb.append(System.getProperty("line.separator"));
                        continue;
                    }
                    for (Map.Entry<String, String> e : xutihuan.entrySet()) {
                        lineTxt = lineTxt.replace("<@spring.message \"" + e.getKey() + "\"", "<@spring.message \"" + e.getValue() + "\"");
                    }
                    sb.append(lineTxt);
                    sb.append(System.getProperty("line.separator"));
                }

                PrintWriter printWriter = new PrintWriter(f1);
                printWriter.write(sb.toString().toCharArray());
                printWriter.close();
                printWriter.flush();

                //提取
            } catch (Exception ex) {
                Logger.getLogger(Replace.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }

    public static void resdString(String fileDir) {
        List<File> fileList = new ArrayList<>();
        File file = new File(fileDir);
        if (file.isFile()) {
            fileList.add(file);
        } else {
            File[] files = file.listFiles();
            if (files == null) {
                return;
            }
            for (File f : files) {
                if (f.isFile()) {
                    fileList.add(f);
                } else if (f.isDirectory()) {
                    resdString(f.getAbsolutePath());
                }
            }
        }

        for (File f1 : fileList) {
            try (InputStreamReader read = new InputStreamReader(new FileInputStream(f1), "UTF-8")) {
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                StringBuilder sb = new StringBuilder();
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    if (lineTxt == null) {
                        continue;
                    }
                    lineTxt.trim();
                    Matcher ma = quchu.matcher(lineTxt);
                    lineTxt = ma.replaceAll("");
                    //System.out.println(lineTxt);
                    if (lineTxt.startsWith("//") || lineTxt.startsWith("/*")
                            || lineTxt.startsWith("@LogOpera") || lineTxt.startsWith("*")
                            || lineTxt.startsWith("*@a")){
                        continue;
                    }
                    //提取中文
                    final Matcher m = p.matcher(lineTxt);
                    while (m.find()) {
                        System.out.println(m.group());
                        result.add(m.group());
                    }
                    sb.append(lineTxt);
                }
                //提取
            } catch (Exception ex) {
                Logger.getLogger(Replace.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }



    public static Map<String, String> readI18n(String path, final int index, final Boolean converUnicode) {

        final Map<String, String> m = new HashMap<>();
        try (InputStreamReader read = new InputStreamReader(new FileInputStream(path), "UTF-8")) {
            BufferedReader bufferedReader = new BufferedReader(read);
            String lineTxt = null;
            StringBuilder sb = new StringBuilder();
            while ((lineTxt = bufferedReader.readLine()) != null) {
                if (lineTxt == null) {
                    continue;
                }
                lineTxt = lineTxt.trim();
                if (lineTxt.endsWith(",")) {
                    lineTxt = lineTxt.substring(0, lineTxt.length() - 1);
                }
                if (converUnicode && convert(lineTxt).trim().length() > 0) {
                    lineTxt = convert(lineTxt);
                }

                String[] ss = lineTxt.split("=", 2);
                if (ss.length < 2) {
                    continue;
                }
                m.put(ss[index], lineTxt);
            }

            //提取
        } catch (Exception ex) {
            Logger.getLogger(Replace.class.getName()).log(Level.SEVERE, null, ex);
        }
        return m;
    }

    public static String convert(String utfString) {
        StringBuilder sb = new StringBuilder();
        int i = -1;
        int pos = 0;

        while ((i = utfString.indexOf("\\u", pos)) != -1) {
            sb.append(utfString.substring(pos, i));
            if (i + 5 < utfString.length()) {
                pos = i + 6;
                sb.append((char) Integer.parseInt(utfString.substring(i + 2, i + 6), 16));
            }
        }
        if (pos < utfString.length()) {
            sb.append(utfString.substring(pos, utfString.length()));
        }
        return sb.toString();
    }

    private static String unicodeToCn(String unicode) {
        String[] strs = unicode.split("\\\\u");
        String returnStr = "";
        for (int i = 1; i < strs.length; i++) {
            returnStr += (char) Integer.valueOf(strs[i], 16).intValue();
        }
        return returnStr;
    }

    private static void tiHuangZhengLi() {

        final Map<String, String> m = new HashMap<>();
        try (InputStreamReader read = new InputStreamReader(new FileInputStream("C:\\Users\\Administrator\\Desktop\\ii\\chufuKEY-Value.txt"), "UTF-8")) {
            BufferedReader bufferedReader = new BufferedReader(read);
            String lineTxt = null;

            final Map<String, String> keyMap = new HashMap<>();
            final Map<String, String> xinMap = new HashMap<>();
            while ((lineTxt = bufferedReader.readLine()) != null) {
                if (lineTxt == null) {
                    continue;
                }
                lineTxt = lineTxt.trim();
                final String[] ss = lineTxt.split("````", 2);
                if (ss.length < 2) {
                    continue;
                }
                final String old = ss[0];
                final String oldKey = ss[0].split("`=`")[0];

                final String xinKey = ss[1].split("`=`")[0];
                final String xinValue = ss[1].split("`=`")[1];

                keyMap.put(oldKey, xinKey);
                xinMap.put(xinKey, xinValue);

            }

            boolean is = false;
            final Map<String, String> xutihuan = new HashMap();
            try (InputStreamReader peoread = new InputStreamReader(new FileInputStream("E:\\workspace\\RuiliAirB2B\\rlairB2B-webcfg\\src\\main\\resources\\i18n\\web\\messages.properties"), "UTF-8")) {
                BufferedReader peoreadbufferedReader = new BufferedReader(peoread);
                String peoreadlineTxt = null;
                StringBuilder peoreadsb = new StringBuilder();

                while ((peoreadlineTxt = peoreadbufferedReader.readLine()) != null) {
                    if (keyMap.containsKey(peoreadlineTxt.split("=", 2)[0])) {
                        is = true;
                        xutihuan.put(peoreadlineTxt.split("=", 2)[0], keyMap.get(peoreadlineTxt.split("=", 2)[0]));
                        peoreadlineTxt = keyMap.get(peoreadlineTxt.split("=", 2)[0]) + "=" + xinMap.get(keyMap.get(peoreadlineTxt.split("=", 2)[0]));
                    }
                    peoreadsb.append(peoreadlineTxt);
                    peoreadsb.append(System.getProperty("line.separator"));
                }

                PrintWriter printWriter = new PrintWriter("E:\\workspace\\RuiliAirB2B\\rlairB2B-webcfg\\src\\main\\resources\\i18n\\web\\messages.properties");
                printWriter.write(peoreadsb.toString().toCharArray());
                printWriter.close();
                printWriter.flush();

            } catch (Exception ex) {
                Logger.getLogger(Replace.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (!xutihuan.isEmpty() && is) {
                //去替换FTL
                replace("E:\\workspace\\RuiliAirB2B\\rlairB2B-webcfg\\src\\main\\webapp\\WEB-INF\\views", xutihuan);
            }

            //修改中文i18n
            try (InputStreamReader peoread = new InputStreamReader(new FileInputStream("E:\\workspace\\RuiliAirB2B\\rlairB2B-webcfg\\src\\main\\resources\\i18n\\web\\messages_zh_CN.properties"), "UTF-8")) {
                BufferedReader peoreadbufferedReader = new BufferedReader(peoread);
                String peoreadlineTxt = null;
                StringBuilder peoreadsb = new StringBuilder();

                while ((peoreadlineTxt = peoreadbufferedReader.readLine()) != null) {
                    if (keyMap.containsKey(peoreadlineTxt.split("=", 2)[0])) {
                        is = true;
                        xutihuan.put(peoreadlineTxt.split("=", 2)[0], keyMap.get(peoreadlineTxt.split("=", 2)[0]));
                        peoreadlineTxt = keyMap.get(peoreadlineTxt.split("=", 2)[0]) + "=" + peoreadlineTxt.split("=", 2)[1];
                    }
                    peoreadsb.append(peoreadlineTxt);
                    peoreadsb.append(System.getProperty("line.separator"));
                }

                PrintWriter printWriter = new PrintWriter("E:\\workspace\\RuiliAirB2B\\rlairB2B-webcfg\\src\\main\\resources\\i18n\\web\\messages_zh_CN.properties");
                printWriter.write(peoreadsb.toString().toCharArray());
                printWriter.close();
                printWriter.flush();

            } catch (Exception ex) {
                Logger.getLogger(Replace.class.getName()).log(Level.SEVERE, null, ex);
            }

            //提取
        } catch (Exception ex) {
            Logger.getLogger(Replace.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
